package com.itheima.duotai6;

public class Test {
    public static void main(String[] args) {
     /*   Cat cat = creatCat();
        cat.eat();
        cat.drink();

        Dog dog = creatDog();
        dog.eat();
        dog.drink();*/
        Animal animal = creatAnimal();
        animal.drink();
        animal.eat();

    }

    //定义一个方法  生成一个 动物
    //参数  没有
    //返回值 一个动物
    public static Dog creatDog(){
        return new Dog();
    }
    public static Cat creatCat(){
        return new Cat();
    }
    public static Animal creatAnimal(){
        return new Dog();
       // return new Cat();
    }

}
abstract class Animal{
    public void drink(){
        System.out.println("动物喝水");
    }
    public abstract  void eat();
}
class Dog extends Animal{

    @Override
    public void eat() {
        System.out.println("狗吃骨头");
    }
}class Cat extends Animal{

    @Override
    public void eat() {
        System.out.println("猫吃鱼");
    }
}